package com.itheima.controller;

import com.itheima.common.entity.Result;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController("userSetmealController")
@Slf4j
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    // 获取套餐列表
    @PostMapping("getSetmeal")
    public Result getSetmeal(){
        log.info("获取套餐列表");
        try {
            return new Result(true,"获取套餐列表成功",setmealService.getSetmeal());
        }
        catch (Exception e){
            log.error("获取套餐列表失败: {}", e.getMessage(), e);
            return new Result(false,"获取套餐列表失败");
        }
    }
    //根据id查询套餐详细信息 post/setmeal/findById
    @PostMapping("/findById")
    public Result findById(@RequestParam("id") Integer id){
        log.info("根据id查询套餐:{}", id);
        try {
            return new Result(true, "查询成功", setmealService.findById(id));
        } catch (Exception e) {
            log.error("根据id查询套餐失败: {}", e.getMessage(), e);
            return new Result(false, "查询失败");
        }
    }
}
